//
//  WorkViewController.m
//  Learn
//
//  Created by cjg.mini on 2024/3/28.
//  Copyright © 2024 cjg. All rights reserved.
//

#import "WorkViewController.h"
#import "HomeworkAfterClassController.h"
#import "ComputerRoomExamController.h"
#import "TeachingViewController.h"
#import "ClockinViewController.h"

#import "ListenTestViewController.h"
#import "TextbookChapterDetailModel.h"
#import "TextbookQuestionsModel.h"
@interface WorkViewController ()
@property (nonatomic, strong) UIScrollView *mainScroll;
@property (nonatomic, strong) UIView *lineView;
@end

@implementation WorkViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"gotoHearSayPage"];
    [self reloadWebviewWithUrl:H5_API_homework];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"gotoHearSayPage"];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
   
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
   // [self setUI];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.webView];
    self.ingoreTitle = YES;
    self.webView.y = 0;
    self.webView.height = self.view.height - SafeAreaBottomHeight - lTabBarHeight;
    [self reloadWebviewWithUrl:H5_API_homework];
    
}
- (void)wb_userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
{
   
   
    if ([message.name isEqualToString:@"gotoHearSayPage"]) {
        NSDictionary *dic = message.body;
        ListenTestViewController *vc = [[ListenTestViewController alloc] init];
        HsrModel *hr = [HsrModel new];
        hr.resourceName = dic[@"resourceName"];
        hr.versionId = dic[@"versionId"];
        vc.mission_id = [NSString stringWithFormat:@"%@",dic[@"mission_id"]];
        vc.model = hr;
        [self.navigationController pushViewController:vc animated:YES];
    }
    
}
//- (void)setUI {
//    NSArray *list = @[@"课后作业",@"机房考试",@"课堂教学",@"打卡"];
//    self.mainScroll = [[UIScrollView alloc] init];
////    self.mainScroll.delegate = self;
//    self.mainScroll.pagingEnabled = NO;
//    self.mainScroll.scrollEnabled = NO;
//    self.mainScroll.showsHorizontalScrollIndicator = NO;
//    self.mainScroll.frame=CGRectMake(0, NavigationBarHeight, SCREEN_W * list.count, SCREEN_H - NavigationBarHeight - SafeAreaBottomHeight - 49);
//    WeakSelf(self)
//
//    [self.view addSubview:self.mainScroll];
//    for (int i = 0; i < list.count; i++) {
//        UIButton *titleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//        titleBtn.tag = 1234567891 + i;
//        [titleBtn setTitle:list[i] forState:UIControlStateNormal];
//        if (i == 0) {
//            [titleBtn setTitleColor:rgba(12, 183, 108, 1) forState:UIControlStateNormal];
//        } else {
//            [titleBtn setTitleColor:rgba(51, 51, 51, 1) forState:UIControlStateNormal];
//        }
//        titleBtn.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:18];
//        [titleBtn bk_whenTapped:^{
//            [weakself.mainScroll setContentOffset:CGPointMake(SCREEN_W * i, 0) animated:YES];
//            
//            for (int j = 0; j < list.count; j++) {
//                UIButton *sender = [self.view viewWithTag:1234567891 + j];
//                [sender setTitleColor:rgba(51, 51, 51, 1) forState:UIControlStateNormal];
//            }
//
//            [titleBtn setTitleColor:rgba(12, 183, 108, 1) forState:UIControlStateNormal];
//            [weakself.lineView mas_updateConstraints:^(MASConstraintMaker *make) {
//                make.top.equalTo(self.view.mas_top).offset(k_StatusBarHeight + 39);
//                make.left.equalTo(self.view.mas_left).offset(i * SCREEN_W/list.count + (SCREEN_W/list.count/2 - 14));
//                make.width.offset(28);
//                make.height.offset(3);
//            }];
//        }];
//        [self.view addSubview:titleBtn];
//        [titleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(self.view.mas_left).offset(SCREEN_W/list.count * i);
//            make.top.equalTo(self.view.mas_top).offset(k_StatusBarHeight + 2);
//            make.height.offset(42);
//            make.width.offset(SCREEN_W/list.count);
//        }];
//        
//        if (i == 0) {
//            HomeworkAfterClassController *afterVC = [[HomeworkAfterClassController alloc]init];
//            afterVC.view.frame = CGRectMake(0, 0, SCREEN_W, SCREEN_H - NavigationBarHeight - SafeAreaBottomHeight - 49);
//            [self.mainScroll addSubview:afterVC.view];
//            [self addChildViewController:afterVC];
//        }
//        if (i == 1) {
//            ComputerRoomExamController *computVC = [[ComputerRoomExamController alloc]init];
//            computVC.view.frame = CGRectMake(SCREEN_W, 0, SCREEN_W, SCREEN_H - NavigationBarHeight - SafeAreaBottomHeight - 49);
//            [self.mainScroll addSubview:computVC.view];
//            [self addChildViewController:computVC];
//        }
//        if (i == 2) {
//            TeachingViewController *teachingVC = [[TeachingViewController alloc]init];
//            teachingVC.view.frame = CGRectMake(SCREEN_W * 2, 0, SCREEN_W, SCREEN_H - NavigationBarHeight - SafeAreaBottomHeight - 49);
//            [self.mainScroll addSubview:teachingVC.view];
//            [self addChildViewController:teachingVC];
//        }
//        if (i == 3) {
//            ClockinViewController *clockVC = [[ClockinViewController alloc]init];
//            clockVC.view.frame = CGRectMake(SCREEN_W * 3, 0, SCREEN_W, SCREEN_H - NavigationBarHeight - SafeAreaBottomHeight - 49);
//            [self.mainScroll addSubview:clockVC.view];
//            [self addChildViewController:clockVC];
//        }
//    }
//    
//    UIView *lineView = [[UIView alloc] init];
//    lineView.backgroundColor = rgba(12, 183, 108, 1);
//    lineView.layer.cornerRadius = 1.5;
//    lineView.layer.masksToBounds = YES;
//    [self.view addSubview:lineView];
//    self.lineView = lineView;
//    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.view.mas_top).offset(k_StatusBarHeight + 39);
//        make.left.equalTo(self.view.mas_left).offset(SCREEN_W/list.count/2 - 14);
//        make.width.offset(28);
//        make.height.offset(3);
//    }];
//    
//    
//}

//- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
//
//}
@end
